/********************************************************************************/
/** dmb This was done so averages can be taken of the rating in gridviews     **/
/**   note that data entry is still presently limited to a list of integers   */
/******************************************************************************/

USE image
GO

DROP TABLE [dbo].[UserImageRating]

-- Creating table 'UserImageRating'
CREATE TABLE [dbo].[UserImageRating] (
    [user_image_rating_id] int  IDENTITY (1,1) NOT NULL,
    [userid] int  NOT NULL,
    [imageid] int  NOT NULL,
    [rating] numeric(2,1)  NOT NULL,
    [rating_date] datetime NOT NULL
);
GO

ALTER TABLE [dbo].[UserImageRating]
ADD CONSTRAINT [PK_UserImageRating]
    PRIMARY KEY CLUSTERED ([user_image_rating_id] ASC);
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_UserImageRating2'
CREATE INDEX [IX_FK_UserImageRating2]
ON [dbo].[UserImageRating]
    ([imageid]);
GO

-- Creating foreign key on [imageid] in table 'UserImageRating'
ALTER TABLE [dbo].[UserImageRating]
ADD CONSTRAINT [FK_UserImageRating2]
    FOREIGN KEY ([imageid])
    REFERENCES [dbo].[Image]
        ([imageid])
    ON DELETE CASCADE ON UPDATE NO ACTION;